﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrapeCity.ActiveReports;
using GrapeCity.ActiveReports.PageReportModel;
using System.Data;
using System.Web;
using System.Web.UI;

namespace WebApplication16
{
    class ClsPageReport
    {

        public PageReport CreateReport()
        {
            GrapeCity.ActiveReports.PageReport _pageReport = new GrapeCity.ActiveReports.PageReport();
            _pageReport.Load(new System.IO.FileInfo("D:\\ActiveReports\\WebApplication16\\WebApplication16\\RdlReport1.rdlx"));
            _pageReport.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(pageDocument_LocateDataSource);
           
            return _pageReport;

        }

        private void pageDocument_LocateDataSource(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
        {
            if (args.DataSetName == "DataSet2")
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("aaa");
                System.Data.DataRow dr = dt.NewRow();
                dr["aaa"] = "1900-01-02";
                dt.Rows.Add(dr);
                args.Data = dt;
            }
            else
            {
                args.Data = GetDataSource();
            }
        }

        private DataTable GetDataSource()
        {
            string connStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};","D:\\ActiveReports\\WebApplication16\\WebApplication16\\NWind_CHS.mdb");
            string productSql = string.Format("SELECT * From 入库单 where 入库单ID = '1' ");
            DataLayer dl = new DataLayer(connStr, productSql);
            return dl.DataSetData.Tables["Products"];
        }

        }
}
